class Solution(object):
    def maxDiff(self, num):
        num = str(num)
        n = len(num)
        max_num = num
        min_num = num
        for i in range(n):
            if num[i] != '9':
                max_num = num.replace(num[i], '9')
                break
        for i in range(n):
            if i == 0:
                if num[i] != '1':
                    min_num = num.replace(num[i], '1')
                    break
            else:
                if num[i] != '0' and num[i] != '1':
                    min_num = num.replace(num[i], '0')
                    break
        return int(max_num) - int(min_num)